package com.oocl.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.oocl.pojo.Customer;
import com.oocl.service.CustomerService;
import com.oocl.service.impl.ServiceFactory;


@Controller
public class CustomerController {

	private static CustomerService customerService;
	
	public CustomerController() {
		System.out.println("实例化controller!");
		customerService = ServiceFactory.getCustomerManager();
	}
	
	@RequestMapping(value="/addCustomer",method=RequestMethod.POST)
	public String addCustomer(Customer customer,Model model){
		customerService.addCustomer(customer);
		System.out.println("添加customer:" + customer);
		return "redirect:/listAll";
	}
	
	@RequestMapping(value="/listAll")
	public String findAllCustomer(Model model){
		List<Customer> customers = customerService.listCustomer();
		System.out.println("所有Custom：" + customers);
		model.addAttribute("customers", customers);
		return "show";
	}
	
	
	
	
}
